// 接口公共部分
// let defaultUrl = 'http://localhost:12315',
// let defaultUrl = 'http://v2440e7437.wicp.vip',
// let defaultUrl = 'http://192.168.0.120:12315',
let defaultUrl = 'https://member.da-sun.cn',
    time = 0;


export const request = (params) => {
  let token = wx.getStorageSync('token');
  let header = { ...params.header }
  if (token) {
    header.xcxLoginToken = token
  }
  time++
  wx.showLoading({
    title: '数据加载中……',
    mask: true
  });
    
  return new Promise((resolve, reject) => {
    wx.request({
      ...params,
      header,
      url: defaultUrl + params.url,
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        if (result.data.errCode == 200) {
          if (params.url == '/xcxApi/enterpriseStoreActivityRecord/insert') {
            wx.showToast({
              title: '报名成功！',
              icon: 'success',
              duration: 1500,
              mask: true
            });
          }
          resolve(result.data.data)
        } else {
          wx.showToast({
            title: result.data.errMsg,
            icon: 'none',
            duration: 1500,
            mask: true
          });
        }
      },
      fail: (err) => {
        reject(err)
      },
      complete: (error) => {
        time--
        if (time == 0) {
          wx.hideLoading();
        }
        if (error.statusCode == 500) {
          wx.showToast({
            title: '服务器繁忙！',
            icon: 'error',
            duration: 1500,
            mask: true
          });
        }
      }
    });
      
  })
}